<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>资源列表</title>
</head>
<style>
    .table>tbody>tr>td{
        text-align:center;
    }
</style>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 资源管理 <span class="c-gray en">&gt;</span> 资源列表 <a id="btn-refresh" class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <form id="form-search" class="text-c"> 日期范围：
        <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'maxDate\')||\'%y-%M-%d\'}' })" id="minDate" name="minDate" class="input-text Wdate" style="width:120px;">
        -
        <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'minDate\')}',maxDate:'%y-%M-%d' })" id="maxDate" name="maxDate" class="input-text Wdate" style="width:120px;">
        <span class="select-box" style="width: 100px;">
            <select id="catId" class="select">
                <option value="">资源类型</option>
            </select>
        </span>
        <input type="text" class="input-text" style="width:250px" placeholder="输入会员名称、资源内容等信息" id="searchKey" name="searchKey">
        <button id="searchButton" type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
    </form>
    <div class="mt-20" style="margin-bottom: 70px">
        <table class="table table-border table-bordered table-hover table-bg table-sort" width="100%">
            <thead>
            <tr class="text-c">
                <th width="80">发布者</th>
                <th width="80">发布时间</th>
                <th width="80">联系电话</th>
                <th width="80">类型</th>
                <th width="110">内容</th>
                <th width="100">图片</th>
                <th width="40">操作</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/datatables/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="lib/common.js"></script>
<script type="text/javascript">

    $(document).on('click','td img', function(){
        var src = $(this).attr('src');
        layer.open({
            type: 1,
            title: '',
            content: '<image src="'+ src +'"  style="max-width:300px;"/>'
        });
    });

    function updateStatus(id){
        $.ajax({
            url:"/resource/updateStatus/" + id,
            type: 'POST',
            success:function (data) {
                if(data.success!=true){
                    layer.alert(data.message,{title: '错误信息',icon: 2});
                    return;
                }
                refresh();
                layer.msg('操作成功!',{icon:1,time:1000});
            },
            error:function(XMLHttpRequest){
                if(XMLHttpRequest.status!=200){
                    layer.alert('操作失败! 错误码:'+XMLHttpRequest.status,{title: '错误信息',icon: 2});
                }
            }
        });
    }

    $(function() {

        initCatSelect();

        function initCatSelect(){
            $.ajax({
                url:"/resource/cat/list",
                type: 'GET',
                success:function (data) {
                    if(data.data && data.data.length>0){
                       for(var i=0; i<data.data.length; i++){
                           $('#catId').append('<option value="'+ data.data[i].id +'">'+ data.data[i].name +'</option>')
                       }
                    }
                },
                error:function(XMLHttpRequest){
                    if(XMLHttpRequest.status!=200){
                        layer.alert('获取资源分类失败! 错误码:'+XMLHttpRequest.status,{title: '错误信息',icon: 2});
                    }
                }
            });
        }

        $('.table').dataTable({
            serverSide: true,//开启服务器模式
            "processing": true,//加载显示提示
            "ajax": {
                url:"resource/list",
                type: 'GET',
                data:{
                    "searchKey": "",
                    "minDate": "",
                    "maxDate": ""
                }
            },
            "createdRow": function( row, data, dataIndex ) {
                $(row).children('td').eq(4).css({
                    'overflow':'hidden',
                    'white-space':'nowrap',
                    'max-width':'150px',
                    'text-overflow': 'ellipsis',
                    'text-align': 'left',
                    'cursor': 'pointer'
                });
                $(row).children('td').eq(4).attr('title', data.content);
            },
            "columns": [
                { "data": "memberName"},
                { "data": "created",
                    render : function(data,type, row, meta) {
                        return date(data);
                    }
                },
                { "data": "memberPhone"},
                { "data": "catName"},
                { "data": "content"},
                {
                    "data": "image",
                    render: function (data, type, row, meta) {
                        var html = '';
                        if(data){
                            var images = data.split(",");
                            for(var i=0; i<images.length; i++){
                                html += '<img src="' + images[i] + '" title="点击查看大图" style="cursor: pointer;max-height: 20px;margin-right:10px;" alt="" />'
                            }
                        }
                        return html;
                    }
                },
                { "data": "status",
                    render : function(data,type, row, meta) {
                        var action = data == 0 ? '隐藏' : '显示';
                        return '<a title="'+ action +'" href="javascript:;" class="ml-5" onclick="updateStatus('+ row.id +')" style="text-decoration:none">'+ action +'</a>';
                    }
                }
            ],
            "aaSorting": [[ 1, "desc" ]],//默认第几个排序
            "bStateSave": false,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable":false,"aTargets":[5]}// 制定列不参与排序
            ],
            language: {
                url: '/lib/datatables/Chinese.json'
            },
            colReorder: true
        });

    });

    /*多条件查询*/
    $("#form-search").validate({
        rules:{
            minDate:{
                required:false
            },
            maxDate:{
                required:false
            },
            searchKey:{
                required:false
            }
        },
        onkeyup:false,
        focusCleanup:false,
        success:"valid",
        submitHandler:function(form){
            var searchKey= $('#searchKey').val();
            var minDate= $('#minDate').val();
            var catId= $('#catId').val();
            var maxDate= $('#maxDate').val();
            var param = {
                "searchKey": searchKey,
                "catId":catId,
                "minDate": minDate,
                "maxDate":maxDate
            };
            var table = $('.table').DataTable();
            table.settings()[0].ajax.data = param;
            table.ajax.reload();
        }
    });
</script>
</body>
</html>
